package cn.com.ddapp.ddm.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.MainActivity;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.ClassifyGoodAdpter;
import cn.com.ddapp.ddm.adapter.ClassifyGoodLandAdpter;
import cn.com.ddapp.ddm.adapter.GoodLandBrowAdapter;
import cn.com.ddapp.ddm.adapter.LandsortAdpter;
import cn.com.ddapp.ddm.adapter.LikeGoodLandBrowAdapter;
import cn.com.ddapp.ddm.adapter.SlidingGoodSmallAdpter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.ClassifyGoodBean;
import cn.com.ddapp.ddm.bean.DetailsBean;
import cn.com.ddapp.ddm.bean.SlidingSmallBean;
import cn.com.ddapp.ddm.bean.mine.MyCall;
import cn.com.ddapp.ddm.bean.shopcar.ShopcarEntity;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.StringUtils;
import cn.com.ddapp.ddm.widget.pulltorefresh.PullToRefreshLayout;
import okhttp3.Call;


/**
 * Created by Administrator on 2016/7/29 0029.
 * 横屏的商品列表
 */
public class GoodLandClassifyActivity extends Activity {

    //	@BindView(R.id.clssify_search)
//	EditText clssify_search;
    @BindView(R.id.classify_moren)
    TextView classify_moren;
    @BindView(R.id.classify_sold)
    TextView classify_sold;
    @BindView(R.id.classify_area)
    TextView classify_area;
    @BindView(R.id.classify_more)
    TextView classify_more;
    @BindView(R.id.clssify_list)
    GridView clssify_list;
    @BindView(R.id.empty)
    EmptyLayout emptyLayout;
    @BindView(R.id.empty1)
    EmptyLayout emptyLayout1;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.titletext)
    TextView titletext;
    @BindView(R.id.good_jilu)
    TextView good_jilu;
    @BindView(R.id.land_goodlbtview)
    RecyclerView land_goodlbtview;
    @BindView(R.id.land_goodleftview)
    RecyclerView land_goodleftview;
    @BindView(R.id.slidingsmall_view)
    GridView pinpai_view;
    @BindView(R.id.landsort_fenlei)
    ListView landsort_fenlei;
    @BindView(R.id.all_sort)
    TextView all_sort;
    @BindView(R.id.sort_cartll)
    LinearLayout sort_cartll;
    @BindView(R.id.sort_kefull)
    LinearLayout sort_kefull;
    @BindView(R.id.land_cartnum)
    TextView land_cartnum;
    @BindView(R.id.share_refresh)
    PullToRefreshLayout shareRefresh;

    @BindView(R.id.land_tohome)
    AutoLinearLayout landTohome;
    @BindView(R.id.totalLinearlayout)
    AutoLinearLayout totalLinearlayout;

    private ClassifyGoodAdpter cAdapter;
    private LandsortAdpter newAdapter;
    private ClassifyGoodLandAdpter landcAdapter;
    private List<ClassifyGoodBean.ClassifyGood> nList;
    private int st, alllist;
    private int addrId;
    private Context context;
    private boolean isCheck = false;
    private boolean isNor = false;
    private int state = 0;
    //	private SlidingMenu slidingMenu;
    Unbinder unbinder;
    private String result = "";
    protected Gson gson = new Gson();
    private int brandId, shopcarNum, promotionId;
    private String lId, sortName, userId;
    private List<DetailsBean.BrowseGood> broList;
    private List<DetailsBean.LikeBrandGood> likeList;
    private List<SlidingSmallBean.Paramss> pList;
    private List<SlidingSmallBean.brandList> brandLists;
    private SlidingGoodSmallAdpter smallAdpter;
    private BrandBroact bBrocast = new BrandBroact();
    private PinPaiBroact pBrocast = new PinPaiBroact();
    private String paramIds, myPhone, classiftId;
    private HashMap<String, Boolean> checkIs;

    public static void startIntent(Context context) {
        Intent intent = new Intent(context, GoodLandClassifyActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landgoodclassify);


        unbinder = ButterKnife.bind(this);
        lId = SPUtils.getStringData(getApplicationContext(), SPUtils.LID);
        userId = SPUtils.getStringData(GoodLandClassifyActivity.this, SPUtils.USERID);
        sortName = getIntent().getStringExtra("sortName");
        titletext.setText(sortName);
        classiftId = getIntent().getStringExtra("classiftId");
        promotionId = getIntent().getIntExtra("promotionId", 0);//更多特色专享的Id
        Log.i("aaa", "--arid--" + AppConfig.CITY_ID);
        brandId = getIntent().getIntExtra("brandId", 0);
        initLandView();
        getBrand();
        getCoustomPhone();
        getGoodData();//相同场景应用商品和浏览历史
        if (!TextUtils.isEmpty(userId)) {
            getShopNum();//购物车的数量
        } else {
            land_goodlbtview.setVisibility(View.GONE);
            land_goodleftview.setVisibility(View.GONE);
        }
        initBroast();
    }

    private void getCoustomPhone() {
        final OkUtilCallback callback1 = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                Gson gson = new Gson();
                MyCall call = gson.fromJson(response, MyCall.class);
                if (call.getContent() != null) {
                    myPhone = call.getContent();
                }
            }
        };
        //客服热线
        OKUtilAPI.post(OKUtilAPI.art, "type=4", callback1);

    }

    /**
     * 获取购物车的数量
     */
    private void getShopNum() {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                ShopcarEntity entity = gson.fromJson(response, ShopcarEntity.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else {
                    shopcarNum = entity.getList().get(0).getGoodsList().size();
                    land_cartnum.setText(shopcarNum + "");
                }
            }
        };
        OKUtilAPI.post(OKUtilAPI.shopList, "userId=" + userId + "&addrId=" + AppConfig.CITY_ID, okUtilCallback);
    }

    private void initBroast() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("bbId");
        registerReceiver(bBrocast, filter);
        IntentFilter pfilter = new IntentFilter();
        pfilter.addAction("pinpaiId");
        registerReceiver(pBrocast, pfilter);

    }

    private class BrandBroact extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("bbId")) {
                String bId = intent.getStringExtra("bbId");
                if (!TextUtils.isEmpty(bId)) {
                    reequestLandData(false,0, 0, 0, result, classiftId, brandId, bId);
                } else {
                    reequestLandData(false,0, 0, 0, result, classiftId, brandId, paramIds);
                }
            }
        }
    }

    private class PinPaiBroact extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("pinpaiId")) {
                int bId = intent.getIntExtra("pinpaiId", 0);
                if (bId != 0) {
                    reequestLandData(false,0, 0, 0, result, classiftId, bId, paramIds);
                } else {
                    reequestLandData(false,0, 0, 0, result, classiftId, 0, paramIds);
                }
            }
        }
    }


    private void getBrand() {
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                SlidingSmallBean bean = gson.fromJson(response, SlidingSmallBean.class);
                if (!bean.getResult().equals("OK")) {
                    BaseApplication.getIntstance().showToast(bean.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else {
                    brandLists = bean.getBrandList();
//                    siteList=bean.getSiteList();
//                    hairLists=bean.getHairList();
                    smallAdpter = new SlidingGoodSmallAdpter(context, brandLists);
//                    siteAdapter=new SlidingsiteAdpter(context,siteList);
//                    hairAdapter=new SlidinghairAdpter(context,hairLists);
                    pinpai_view.setAdapter(smallAdpter);
                    smallAdpter.clear();
                    pinpai_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            toreset();

                            setTextAllNorColor(all_sort);
                            isNor = true;
                            brandId = brandLists.get(i).getId();
                            reequestLandData(false,0, 0, 0, result, classiftId, brandId, paramIds);
                        }
                    });
                    pList = bean.getParams();
                    newAdapter = new LandsortAdpter(context, pList);
                    landsort_fenlei.setAdapter(newAdapter);
//                    huapao_view.setAdapter(hairAdapter);
//                    site_view.setAdapter(siteAdapter);
//                    pinpai_view.setOnItemClickListener(pinpaiListener);

                }
            }
        };
        String params = "levelId=" + classiftId;
        OKUtilAPI.post(OKUtilAPI.condition, params, okUtilCallback);
    }

    private void toreset() {
//        for(int a=0;a<brandLists.size();a++){
//            TextView tt= (TextView) pinpai_view.getChildAt(a).findViewById(R.id.slidingsmall_name);
//            tt.setTextColor(getResources().getColor(R.color.main_gray));
//            tt.setBackgroundResource(R.color.white);
//        }
    }

    private void getGoodData() {
        emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
        final OkUtilCallback okUtilCallback = new OkUtilCallback(emptyLayout) {
            @Override
            public void onMyResponse(String response, int id) {
                DetailsBean detailsBean = gson.fromJson(response, DetailsBean.class);
                if (!detailsBean.getResult().equals("OK")) {
                    BaseApplication.showToast(detailsBean.getResult());
                } else {
                    broList = detailsBean.getBrowseGoods();
                    likeList = detailsBean.getLikeBrandGoods();
                    if (broList != null && broList.size() > 0) {
                        land_goodlbtview.setVisibility(View.VISIBLE);
                        initBrohis();//浏览历史
                    } else {
                        land_goodlbtview.setVisibility(View.GONE);
                    }
                    if (likeList != null && likeList.size() > 0) {
                        land_goodleftview.setVisibility(View.VISIBLE);
                        initLikeGood();//相同场景商品
                    } else {
                        land_goodleftview.setVisibility(View.GONE);
                    }
                }
            }
        };
        String params = "wid=" + AppConfig.CITY_ID + "&id=" + AppConfig.GoodsId + "&userId=" + userId;
        OKUtilAPI.post(OKUtilAPI.CommidUrl, params, okUtilCallback);
    }

    private void initLikeGood() {
        LikeGoodLandBrowAdapter guessAdapter = new LikeGoodLandBrowAdapter(GoodLandClassifyActivity.this, likeList);
        land_goodleftview.setAdapter(guessAdapter);
        land_goodleftview.setLayoutManager(new LinearLayoutManager(GoodLandClassifyActivity.this, LinearLayoutManager.VERTICAL, false));
        guessAdapter.setOnItemClickListener(new LikeGoodLandBrowAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int i) {
                Intent intent = new Intent(GoodLandClassifyActivity.this, CommidContentActivity.class);
                int id = likeList.get(i).getId();
                intent.putExtra("type","id");
                intent.putExtra("id", String.valueOf(id));
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int position) {

            }
        });
    }

    private void initBrohis() {
        GoodLandBrowAdapter guessAdapter = new GoodLandBrowAdapter(GoodLandClassifyActivity.this, broList);
        land_goodlbtview.setAdapter(guessAdapter);
        land_goodlbtview.setLayoutManager(new LinearLayoutManager(GoodLandClassifyActivity.this, LinearLayoutManager.VERTICAL, false));
        guessAdapter.setOnItemClickListener(new GoodLandBrowAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int i) {
                Intent intent = new Intent(GoodLandClassifyActivity.this, CommidContentActivity.class);
                int id = broList.get(i).getId();
                intent.putExtra("type","id");
                intent.putExtra("id", String.valueOf(id));
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int position) {

            }
        });
    }

    private void initLandView() {


        shareRefresh.setIfCanPullDown(false);
        emptyLayout1.setClickable(false);
        addrId = getIntent().getIntExtra("addrId", 1);
        result = getIntent().getStringExtra("searchResult");  //搜索的字段
        context = getApplicationContext();
        reequestLandData(true,0, 0, 0, result, classiftId, brandId, paramIds);
        shareRefresh.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
			@Override
			public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
//                reequestLandData(true,0, 0, 0, result, classiftId, brandId, paramIds);
			}

			@Override
			public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
                reequestLandData(false,st, 0, 0, result, classiftId, brandId, paramIds);
			}
		});
        nList = new ArrayList<>();
    }


    private void reequestLandData(final boolean headrefresh , final int a, final int sort, final int sortype, final String name, final String leveid, final int brandId, final String paramIds) {
        try {

            emptyLayout1.setErrorType(EmptyLayout.NETWORK_LOADING);
            final OkUtilCallback okUtilCallback = new OkUtilCallback(emptyLayout1) {
                @Override
                public void onMyResponse(String response, int id) {
                    if(headrefresh){
                        st=0;
                    }
                    ClassifyGoodBean entity = gson.fromJson(response, ClassifyGoodBean.class);
                    if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                        emptyLayout1.setErrorType(EmptyLayout.NODATA);
                        BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.TOP);
                    } else if ((entity.getResult().equals("OK") && entity.getList().size() == 0)&&headrefresh) {
                        emptyLayout1.setErrorType(EmptyLayout.NODATA);
                        good_jilu.setText("共计 " + 0 + " 个记录");
                        clssify_list.setVisibility(View.GONE);
                    } else {
//                        if(headrefresh){
//                            shareRefresh.refreshFinish(PullToRefreshLayout.SUCCEED);
//                        }
                        if(a == 0){
                            nList.clear();
                            nList = entity.getList();
                        }else{
                            nList.addAll(entity.getList());
                        }
                        clssify_list.setVisibility(View.VISIBLE);
                        Log.i("aaa", "--a--" + nList.size());
                        alllist = nList.size();
                        landcAdapter = new ClassifyGoodLandAdpter(context, nList);
                        clssify_list.setAdapter(landcAdapter);
                        clssify_list.setNumColumns(4);
                        good_jilu.setText("共计 " + alllist + " 个记录");
                        clssify_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                Intent intent = new Intent(getApplicationContext(), CommidContentActivity.class);
                                int id = nList.get(i).getId();
                                Log.e("IDS", "ID===========" + id);
                                intent.putExtra("type","id");
                                intent.putExtra("id", String.valueOf(id));
                                startActivity(intent);
                            }

                        });
                        if(st >0){
                                shareRefresh.loadmoreFinish(PullToRefreshLayout.SUCCEED);
                        }
                        if(alllist != 0){
                            st = st + entity.getList().size();
                        }

                    }
                }
                @Override
                public void onError(Call call, Exception e, int id) {
                    super.onError(call, e, id);
                    emptyLayout1.setErrorType(EmptyLayout.NODATA);
                }
            };
            String params = "";
            if (promotionId != 0) {
                params = "addrId=" + AppConfig.CITY_ID + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype + "&promotionId=" + promotionId;
                if(brandId!=0){
                    params = params + "&brandId=" + brandId;
                }
                if(!StringUtils.isEmpty(paramIds)){
                    params = params + "&paramIds=" + paramIds;
                }
//                promotionId = 0;
            } else {
                if (TextUtils.isEmpty(name) && brandId == 0) {
                    params = "addrId=" + AppConfig.CITY_ID + "&sortLevel=" + leveid + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype;
                }
                if (TextUtils.isEmpty(name) && brandId != 0) {
                    params = "addrId=" + AppConfig.CITY_ID + "&sortLevel=" + leveid + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype + "&brandId=" + brandId;
                }
                if (brandId != 0 && TextUtils.isEmpty(name)) {
                    params = "addrId=" + AppConfig.CITY_ID + "&sortLevel=" + leveid + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype + "&brandId=" + brandId;
                }
                if (!TextUtils.isEmpty(name)) {
                    params = "addrId=" + AppConfig.CITY_ID + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype + "&key=" + name;
                }
                if (name == null && brandId == 0 && !TextUtils.isEmpty(paramIds)) {
                    params = "addrId=" + AppConfig.CITY_ID + "&sortLevel=" + leveid + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype + "&paramIds=" + paramIds;
                }
                if (name == null && brandId == 0 && leveid.equals("0")) {
                    params = "addrId=" + AppConfig.CITY_ID + "&st=" + a + "&sort=" + sort + "&sortType=" + sortype;
                }
            }
            OKUtilAPI.post(OKUtilAPI.goodclassify, params, okUtilCallback);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
//	private void reequestMoreLandData(final int a,final int sort,final int sortype,final String name,final String leveid,final int brandId) {
//		emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
//		final OkUtilCallback okUtilCallback = new OkUtilCallback(emptyLayout) {
//			@Override
//			public void onMyResponse(String response, int id) {
//				ClassifyGoodBean entity = gson.fromJson(response, ClassifyGoodBean.class);
//				if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
//					BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.TOP);
//				}else{
//					List<ClassifyGoodBean.ClassifyGood> ll=entity.getList();
//					if(ll.size()>0){
//						landcAdapter.addView(ll);
////						clssify_refresh.refreshFinish(PullToRefreshLayout.SUCCEED);
//						st=a;
//					}else{
////						clssify_refresh.loadmoreFinish(PullToRefreshLayout.NODATA);
//					}
//
//				}
//			}
//
//		};
//		String params="";
//        if(TextUtils.isEmpty(name) && brandId==0){
//            params="addrId="+AppConfig.CITY_ID+"&sortLevel="+leveid+"&st="+a+"&sort="+sort+"&sortType="+sortype;
//        }
//		if(TextUtils.isEmpty(name) && brandId!=0 ){
//			params="addrId="+AppConfig.CITY_ID+"&sortLevel="+leveid+"&st="+a+"&sort="+sort+"&sortType="+sortype+"&brandId="+brandId;
//		} if(brandId !=0 && TextUtils.isEmpty(name)){
//            params="addrId="+AppConfig.CITY_ID+"&st="+a+"&sort="+sort+"&sortType="+sortype+"&brandId="+brandId;
//        }
//        if(!TextUtils.isEmpty(name)){
//			params="addrId="+AppConfig.CITY_ID+"&sortLevel="+leveid+"&st="+a+"&sort="+sort+"&sortType="+sortype+"&key="+name;
//		}
//        if(TextUtils.isEmpty(name) && brandId==0 && leveid.equals("0")){
//            params="addrId="+AppConfig.CITY_ID+"&st="+a+"&sort="+sort+"&sortType="+sortype;
//        }
//		OKUtilAPI.post(OKUtilAPI.goodclassify, params, okUtilCallback);
//	}


    private Dialog dialog;

    /**
     * sort int[N]  排序 0: 价格，1:销量 默认价格
     * sortType int[N] 0:升序 1:降序 默认升序
     * sortLevel String[N] 分类级别ID
     * st int[N] 开始读取的行  默认0
     *
     * @param v
     */
    @OnClick({R.id.back, R.id.img_error_layout, R.id.classify_moren, R.id.classify_sold, R.id.classify_area,
            R.id.clssify_search, R.id.all_sort, R.id.sort_cartll, R.id.sort_kefull, R.id.land_tohome})
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.all_sort:
                if (isNor) {
                    setTextAllColor(all_sort);
                    isNor = false;
                    toreset();
                    reequestLandData(false,0, 1, 1, result, classiftId, 0, paramIds);
                } else {
                    setTextAllNorColor(all_sort);
                    isNor = true;
                }
                break;
            case R.id.img_error_layout:
//                reequestLandData(false,0, 0, 0, "", classiftId, brandId, paramIds);
                break;
            case R.id.classify_moren:
                setTextCurColor(classify_moren);
                setTextResetColor(classify_sold);
                setTextResetColor(classify_area);
                state = 0;
                isCheck = false;
                setTextImage(R.mipmap.arrow_down);
                reequestLandData(true,0, 0, 0, result, classiftId, brandId, paramIds);
                break;
            case R.id.classify_sold:
                setTextCurColor(classify_sold);
                setTextResetColor(classify_moren);
                setTextResetColor(classify_area);
                state = 1;
                isCheck = false;
                setTextImage(R.mipmap.arrow_down);
                reequestLandData(true,0, 1, 1, result, classiftId, brandId, paramIds);
                break;
            case R.id.classify_area:
                setTextCurColor(classify_area);
                setTextResetColor(classify_moren);
                setTextResetColor(classify_sold);
                if (isCheck) {
                    state = 2;
                    isCheck = false;
                    setTextImage(R.mipmap.arrow_d);
                    reequestLandData(true,0, 0, 1, result, classiftId, brandId, paramIds);
                } else {
                    state = 4;
                    isCheck = true;
                    setTextImage(R.mipmap.arrow_u);
                    reequestLandData(true,0, 0, 0, result, classiftId, brandId, paramIds);
                }
                break;
            case R.id.sort_cartll:
                if (!SPUtils.getBooleanData(this, SPUtils.ISLOGIN)) {
                    intent = new Intent(GoodLandClassifyActivity.this, LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getApplicationContext(), MainActivity.class);
                    intent.putExtra("id", 1);
                    AppConfig.TOMAIN="1";
                    startActivity(intent);
                }
                break;
            case R.id.sort_kefull:
                dialog = new Dialog(this);
                dialog.setContentView(R.layout.contact_us_dialog);
                Window window = dialog.getWindow();
                window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                RelativeLayout tocall_us = (RelativeLayout) dialog.findViewById(R.id.tocall_us);
                TextView phone = (TextView) dialog.findViewById(R.id.custom_tell);
                phone.setText("客服热线:" + myPhone);
                dialog.setCanceledOnTouchOutside(true);
                tocall_us.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent gg = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + myPhone));//跳转到拨号界面，同时传递电话号码
                        startActivity(gg);
                        dialog.dismiss();
                    }
                });
                WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
                lp.gravity = Gravity.RIGHT;
                dialog.getWindow().setAttributes(lp);

                try {
                    Context context = dialog.getContext();
                    int divierId = context.getResources().getIdentifier("android:id/titleDivider", null, null);
                    View divider = dialog.findViewById(divierId);
                    divider.setBackgroundColor(Color.TRANSPARENT);
                } catch (Exception e) {
                    //去除Holo主题的蓝色线条
                    e.printStackTrace();
                }
                dialog.show();
                break;
            case R.id.land_tohome:
                intent = new Intent(context, MainActivity.class);
                startActivity(intent);
//                ((MainActivity)getApplicationContext()).showHomePageFragment();
                break;


        }
    }

    private void setTextImage(int resId) {
        Drawable dw = getResources().getDrawable(resId);
        dw.setBounds(0, 0, dw.getMinimumWidth(), dw.getMinimumHeight());
        classify_area.setCompoundDrawables(null, null, dw, null);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unregisterReceiver(bBrocast);
        unregisterReceiver(pBrocast);
    }

    public void setTextCurColor(TextView tv) {
        tv.setTextColor(context.getResources().getColor(R.color.color_orange));
    }

    public void setTextAllColor(TextView tv) {
        tv.setTextColor(context.getResources().getColor(R.color.white));
        tv.setBackgroundResource(R.color.red);
    }

    public void setTextAllNorColor(TextView tv) {
        tv.setTextColor(context.getResources().getColor(R.color.gray));
        tv.setBackgroundResource(R.color.white);
    }

    public void setTextResetColor(TextView tv) {
        tv.setTextColor(context.getResources().getColor(R.color.text_color_greyer));
    }
}
